package gui;

import br.com.javac.v200.procnfe.TNfeProc;
import java.awt.event.KeyEvent;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
import lx300.EmissorLX300;
import modelo.Cliente;
import modelo.Motorista;
import modelo.ctrc;
import modelo.dao.ClienteJpaController;
import modelo.dao.MotoristaJpaController;
import util.ManangerEntity;
import util.Mensagem;
import util.MaiusculaLimitadaAsg;

public class GUICtrcMatricial extends javax.swing.JFrame {

    private File arquivo;
    Date data = new Date(System.currentTimeMillis());
    SimpleDateFormat formatarDate = new SimpleDateFormat("dd/MM/yyyy");
    ClienteJpaController dao = new ClienteJpaController(ManangerEntity.getEntityManagerFactory());
    MotoristaJpaController daoMot = new MotoristaJpaController(ManangerEntity.getEntityManagerFactory());

    public GUICtrcMatricial() {
        initComponents();
        setLocationRelativeTo(null);
        IniciaStatusBar();
        tfData.setText(formatarDate.format(data));
        tfData.grabFocus();
        tfData.selectAll();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        fcSelecionadorDeArquivo = new javax.swing.JFileChooser();
        bgFrete = new javax.swing.ButtonGroup();
        pnCabecalho = new javax.swing.JPanel();
        jPanel33 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel35 = new javax.swing.JPanel();
        tfArquivo = new javax.swing.JTextField();
        btImportar = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JSeparator();
        jPanel13 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jPanel14 = new javax.swing.JPanel();
        jPanel11 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        tfData = new javax.swing.JTextField();
        try{
            javax.swing.text.MaskFormatter data= new javax.swing.text.MaskFormatter("##/##/####");
            data.setValidCharacters(" 1234567890");
            tfData = new javax.swing.JFormattedTextField(data);
        }
        catch (Exception e){
        }
        jPanel31 = new javax.swing.JPanel();
        jLabel28 = new javax.swing.JLabel();
        tfNatureza = new javax.swing.JTextField();
        jPanel32 = new javax.swing.JPanel();
        jLabel29 = new javax.swing.JLabel();
        jTextField21 = new javax.swing.JTextField();
        jPanel34 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        pnCentral = new javax.swing.JPanel();
        jPanel15 = new javax.swing.JPanel();
        pnRemetente = new javax.swing.JPanel();
        jPanel16 = new javax.swing.JPanel();
        lbrCodigo = new javax.swing.JLabel();
        lbrRemetente = new javax.swing.JLabel();
        lbrEndereco = new javax.swing.JLabel();
        lbrCidade = new javax.swing.JLabel();
        lbrCnpj = new javax.swing.JLabel();
        lbrIe = new javax.swing.JLabel();
        jPanel17 = new javax.swing.JPanel();
        tfrCodigo = new javax.swing.JTextField();
        tfrRemetente = new javax.swing.JTextField();
        tfrEndereco = new javax.swing.JTextField();
        tfrCidade = new javax.swing.JTextField();
        tfrCidade.setDocument(new MaiusculaLimitadaAsg(50, true));
        tfrCnpj = new javax.swing.JTextField();
        tfrIe = new javax.swing.JTextField();
        pnDestinatario = new javax.swing.JPanel();
        jPanel18 = new javax.swing.JPanel();
        lbdCodigo = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPanel19 = new javax.swing.JPanel();
        tfdCodigo = new javax.swing.JTextField();
        tfdDestinatario = new javax.swing.JTextField();
        tfdEndereco = new javax.swing.JTextField();
        tfdCidade = new javax.swing.JTextField();
        tfdCidade.setDocument(new MaiusculaLimitadaAsg(50, true));
        tfdCnpj = new javax.swing.JTextField();
        tfdIe = new javax.swing.JTextField();
        jPanel30 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jPanel22 = new javax.swing.JPanel();
        jLabel31 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jPanel23 = new javax.swing.JPanel();
        tfCodCarga = new javax.swing.JTextField();
        tfCarga = new javax.swing.JTextField();
        tfNf = new javax.swing.JTextField();
        tfValorNf = new javax.swing.JTextField();
        tfQtdeNf = new javax.swing.JTextField();
        tfEspecie = new javax.swing.JTextField();
        jPanel8 = new javax.swing.JPanel();
        jPanel20 = new javax.swing.JPanel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jPanel21 = new javax.swing.JPanel();
        jTextField13 = new javax.swing.JTextField();
        jTextField14 = new javax.swing.JTextField();
        jTextField15 = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jLabel21 = new javax.swing.JLabel();
        rbPago = new javax.swing.JRadioButton();
        rbAPagar = new javax.swing.JRadioButton();
        jPanel7 = new javax.swing.JPanel();
        jPanel26 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jPanel27 = new javax.swing.JPanel();
        jTextField6 = new javax.swing.JTextField();
        jTextField7 = new javax.swing.JTextField();
        jTextField12 = new javax.swing.JTextField();
        jTextField8 = new javax.swing.JTextField();
        jTextField9 = new javax.swing.JTextField();
        jTextField10 = new javax.swing.JTextField();
        jTextField11 = new javax.swing.JTextField();
        jPanel28 = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        jPanel24 = new javax.swing.JPanel();
        jLabel26 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        jPanel25 = new javax.swing.JPanel();
        tfmCodigo = new javax.swing.JTextField();
        tfmNome = new javax.swing.JTextField();
        tfmCPF = new javax.swing.JTextField();
        tfmCPF.setDocument(new MaiusculaLimitadaAsg(7, true));
        jPanel36 = new javax.swing.JPanel();
        jPanel37 = new javax.swing.JPanel();
        jLabel32 = new javax.swing.JLabel();
        jPanel38 = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        pnObservacao = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel10 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        taObservacoes = new javax.swing.JTextArea();
        jPanel29 = new javax.swing.JPanel();
        jLabel30 = new javax.swing.JLabel();
        pnBotoes = new javax.swing.JPanel();
        jPanel12 = new javax.swing.JPanel();
        btImprimir = new javax.swing.JButton();
        btSair = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Emissão de CTRC Matricial");
        setPreferredSize(new java.awt.Dimension(900, 710));

        pnCabecalho.setBackground(new java.awt.Color(255, 255, 255));
        pnCabecalho.setForeground(new java.awt.Color(255, 255, 255));
        pnCabecalho.setLayout(new java.awt.BorderLayout());

        jPanel33.setLayout(new java.awt.BorderLayout());

        jPanel1.setLayout(new java.awt.BorderLayout());

        jLabel1.setText("Importar de arquivo xml:");
        jPanel1.add(jLabel1, java.awt.BorderLayout.WEST);

        jPanel35.setLayout(new javax.swing.BoxLayout(jPanel35, javax.swing.BoxLayout.LINE_AXIS));

        tfArquivo.setEditable(false);
        jPanel35.add(tfArquivo);

        jPanel1.add(jPanel35, java.awt.BorderLayout.CENTER);

        btImportar.setText("Importar");
        btImportar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btImportarActionPerformed(evt);
            }
        });
        jPanel1.add(btImportar, java.awt.BorderLayout.EAST);
        jPanel1.add(jSeparator3, java.awt.BorderLayout.SOUTH);

        jPanel33.add(jPanel1, java.awt.BorderLayout.CENTER);

        jPanel13.setBackground(new java.awt.Color(255, 255, 255));
        jPanel13.setLayout(new java.awt.BorderLayout());

        jLabel6.setBackground(new java.awt.Color(255, 255, 255));
        jLabel6.setFont(new java.awt.Font("Bookman Old Style", 0, 36)); // NOI18N
        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Matricial48.png"))); // NOI18N
        jLabel6.setText("CTRC MATRICIAL");
        jPanel13.add(jLabel6, java.awt.BorderLayout.PAGE_START);
        jPanel13.add(jSeparator1, java.awt.BorderLayout.SOUTH);

        jPanel33.add(jPanel13, java.awt.BorderLayout.NORTH);

        jPanel14.setLayout(new javax.swing.BoxLayout(jPanel14, javax.swing.BoxLayout.LINE_AXIS));

        jPanel11.setLayout(new java.awt.BorderLayout());

        jLabel5.setText("Data:");
        jPanel11.add(jLabel5, java.awt.BorderLayout.WEST);
        jPanel11.add(tfData, java.awt.BorderLayout.CENTER);

        jPanel14.add(jPanel11);

        jPanel31.setLayout(new java.awt.BorderLayout());

        jLabel28.setText("Natureza");
        jPanel31.add(jLabel28, java.awt.BorderLayout.WEST);

        tfNatureza.setText("TRANSPORTE");
        jPanel31.add(tfNatureza, java.awt.BorderLayout.CENTER);

        jPanel14.add(jPanel31);

        jPanel32.setLayout(new java.awt.BorderLayout());

        jLabel29.setText("Código");
        jPanel32.add(jLabel29, java.awt.BorderLayout.WEST);

        jTextField21.setText("5352");
        jTextField21.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextField21FocusLost(evt);
            }
        });
        jPanel32.add(jTextField21, java.awt.BorderLayout.CENTER);

        jPanel14.add(jPanel32);

        jPanel33.add(jPanel14, java.awt.BorderLayout.SOUTH);

        pnCabecalho.add(jPanel33, java.awt.BorderLayout.CENTER);

        jPanel34.setLayout(new java.awt.BorderLayout());

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel34.add(jButton1, java.awt.BorderLayout.SOUTH);

        pnCabecalho.add(jPanel34, java.awt.BorderLayout.EAST);

        getContentPane().add(pnCabecalho, java.awt.BorderLayout.NORTH);

        pnCentral.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        pnCentral.setLayout(new java.awt.BorderLayout());

        jPanel15.setLayout(new java.awt.GridLayout(1, 0));

        pnRemetente.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED), "Dados Remetente          F2 - Cadastrar/Localizar"));
        pnRemetente.setLayout(new java.awt.BorderLayout());

        jPanel16.setLayout(new java.awt.GridLayout(6, 0));

        lbrCodigo.setText("Código");
        jPanel16.add(lbrCodigo);

        lbrRemetente.setText("Remetente");
        jPanel16.add(lbrRemetente);

        lbrEndereco.setText("Endereço");
        jPanel16.add(lbrEndereco);

        lbrCidade.setText("Cidade");
        jPanel16.add(lbrCidade);

        lbrCnpj.setText("CNPJ");
        jPanel16.add(lbrCnpj);

        lbrIe.setText("IE");
        jPanel16.add(lbrIe);

        pnRemetente.add(jPanel16, java.awt.BorderLayout.WEST);

        jPanel17.setLayout(new java.awt.GridLayout(6, 0));

        tfrCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfrCodigoActionPerformed(evt);
            }
        });
        tfrCodigo.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfrCodigoFocusLost(evt);
            }
        });
        tfrCodigo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfrCodigoKeyPressed(evt);
            }
        });
        jPanel17.add(tfrCodigo);

        tfrRemetente.setEditable(false);
        jPanel17.add(tfrRemetente);

        tfrEndereco.setEditable(false);
        jPanel17.add(tfrEndereco);

        tfrCidade.setEditable(false);
        jPanel17.add(tfrCidade);

        tfrCnpj.setEditable(false);
        jPanel17.add(tfrCnpj);

        tfrIe.setEditable(false);
        jPanel17.add(tfrIe);

        pnRemetente.add(jPanel17, java.awt.BorderLayout.CENTER);

        jPanel15.add(pnRemetente);

        pnDestinatario.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED), "Dados Destinatário          F2 - Cadastrar/Localizar"));
        pnDestinatario.setLayout(new java.awt.BorderLayout());

        jPanel18.setLayout(new java.awt.GridLayout(6, 0));

        lbdCodigo.setText("Código");
        jPanel18.add(lbdCodigo);

        jLabel2.setText("Destinatário");
        jPanel18.add(jLabel2);

        jLabel8.setText("Endereço");
        jPanel18.add(jLabel8);

        jLabel10.setText("Cidade");
        jPanel18.add(jLabel10);

        jLabel12.setText("CNPJ");
        jPanel18.add(jLabel12);

        jLabel3.setText("IE");
        jPanel18.add(jLabel3);

        pnDestinatario.add(jPanel18, java.awt.BorderLayout.WEST);

        jPanel19.setLayout(new java.awt.GridLayout(6, 0));

        tfdCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfdCodigoActionPerformed(evt);
            }
        });
        tfdCodigo.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfdCodigoFocusLost(evt);
            }
        });
        tfdCodigo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfdCodigoKeyPressed(evt);
            }
        });
        jPanel19.add(tfdCodigo);

        tfdDestinatario.setEditable(false);
        jPanel19.add(tfdDestinatario);

        tfdEndereco.setEditable(false);
        jPanel19.add(tfdEndereco);

        tfdCidade.setEditable(false);
        jPanel19.add(tfdCidade);

        tfdCnpj.setEditable(false);
        jPanel19.add(tfdCnpj);

        tfdIe.setEditable(false);
        jPanel19.add(tfdIe);

        pnDestinatario.add(jPanel19, java.awt.BorderLayout.CENTER);

        jPanel15.add(pnDestinatario);

        pnCentral.add(jPanel15, java.awt.BorderLayout.NORTH);

        jPanel30.setLayout(new java.awt.GridLayout(1, 0));

        jPanel3.setLayout(new java.awt.BorderLayout());

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED), "Dados Mercadoria          F2 - Cadastrar/Localizar"));
        jPanel4.setLayout(new java.awt.BorderLayout());

        jPanel22.setLayout(new java.awt.GridLayout(6, 0));

        jLabel31.setText("Código");
        jPanel22.add(jLabel31);

        jLabel4.setText("Nat. Carga");
        jPanel22.add(jLabel4);

        jLabel7.setText("Nota Fiscal");
        jPanel22.add(jLabel7);

        jLabel9.setText("Valor");
        jPanel22.add(jLabel9);

        jLabel11.setText("Qtde");
        jPanel22.add(jLabel11);

        jLabel13.setText("Espécie");
        jPanel22.add(jLabel13);

        jPanel4.add(jPanel22, java.awt.BorderLayout.WEST);

        jPanel23.setLayout(new java.awt.GridLayout(6, 0));
        jPanel23.add(tfCodCarga);
        jPanel23.add(tfCarga);
        jPanel23.add(tfNf);
        jPanel23.add(tfValorNf);
        jPanel23.add(tfQtdeNf);
        jPanel23.add(tfEspecie);

        jPanel4.add(jPanel23, java.awt.BorderLayout.CENTER);

        jPanel3.add(jPanel4, java.awt.BorderLayout.NORTH);

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED), "Cálculo de ICMS"));
        jPanel8.setLayout(new java.awt.BorderLayout());

        jPanel20.setLayout(new java.awt.GridLayout(3, 0));

        jLabel22.setText("Base de Cálculo");
        jPanel20.add(jLabel22);

        jLabel23.setText("Alíquota");
        jPanel20.add(jLabel23);

        jLabel24.setText("ICMS");
        jPanel20.add(jLabel24);

        jPanel8.add(jPanel20, java.awt.BorderLayout.WEST);

        jPanel21.setLayout(new java.awt.GridLayout(3, 0));
        jPanel21.add(jTextField13);
        jPanel21.add(jTextField14);
        jPanel21.add(jTextField15);

        jPanel8.add(jPanel21, java.awt.BorderLayout.CENTER);

        jPanel3.add(jPanel8, java.awt.BorderLayout.CENTER);

        jPanel30.add(jPanel3);

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED), "Dados do Frete"));
        jPanel5.setLayout(new java.awt.BorderLayout());

        jPanel6.setLayout(new javax.swing.BoxLayout(jPanel6, javax.swing.BoxLayout.LINE_AXIS));

        jLabel21.setText("Frete:");
        jPanel6.add(jLabel21);

        bgFrete.add(rbPago);
        rbPago.setSelected(true);
        rbPago.setText("Pago");
        jPanel6.add(rbPago);

        bgFrete.add(rbAPagar);
        rbAPagar.setText("A Pagar");
        jPanel6.add(rbAPagar);

        jPanel5.add(jPanel6, java.awt.BorderLayout.NORTH);

        jPanel7.setLayout(new java.awt.BorderLayout());

        jPanel26.setLayout(new java.awt.GridLayout(7, 0));

        jLabel14.setText("Frete Peso");
        jPanel26.add(jLabel14);

        jLabel15.setText("Km Percorrido");
        jPanel26.add(jLabel15);

        jLabel16.setText("Tarifa");
        jPanel26.add(jLabel16);

        jLabel17.setText("Valor do Frete");
        jPanel26.add(jLabel17);

        jLabel18.setText("Pedágio");
        jPanel26.add(jLabel18);

        jLabel19.setText("Outro");
        jPanel26.add(jLabel19);

        jLabel20.setText("Total do Frete");
        jPanel26.add(jLabel20);

        jPanel7.add(jPanel26, java.awt.BorderLayout.WEST);

        jPanel27.setLayout(new java.awt.GridLayout(7, 0));
        jPanel27.add(jTextField6);
        jPanel27.add(jTextField7);
        jPanel27.add(jTextField12);
        jPanel27.add(jTextField8);
        jPanel27.add(jTextField9);
        jPanel27.add(jTextField10);
        jPanel27.add(jTextField11);

        jPanel7.add(jPanel27, java.awt.BorderLayout.CENTER);

        jPanel5.add(jPanel7, java.awt.BorderLayout.CENTER);

        jPanel30.add(jPanel5);

        pnCentral.add(jPanel30, java.awt.BorderLayout.CENTER);

        jPanel28.setLayout(new java.awt.GridLayout(1, 0));

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED), "Dados Motorista               F2 - Cadastrar/Localizar"));
        jPanel9.setLayout(new java.awt.BorderLayout());

        jPanel24.setLayout(new java.awt.GridLayout(3, 0));

        jLabel26.setText("Código");
        jPanel24.add(jLabel26);

        jLabel25.setText("Nome");
        jPanel24.add(jLabel25);

        jLabel27.setText("Cpf");
        jPanel24.add(jLabel27);

        jPanel9.add(jPanel24, java.awt.BorderLayout.WEST);

        jPanel25.setLayout(new java.awt.GridLayout(3, 0));

        tfmCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfmCodigoActionPerformed(evt);
            }
        });
        tfmCodigo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tfmCodigoKeyPressed(evt);
            }
        });
        jPanel25.add(tfmCodigo);

        tfmNome.setEditable(false);
        jPanel25.add(tfmNome);

        tfmCPF.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfmCPFFocusLost(evt);
            }
        });
        jPanel25.add(tfmCPF);

        jPanel9.add(jPanel25, java.awt.BorderLayout.CENTER);

        jPanel28.add(jPanel9);

        jPanel36.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED), "Dados Veículo          F2 - Cadastrar/Localizar"));
        jPanel36.setLayout(new java.awt.BorderLayout());

        jPanel37.setLayout(new java.awt.GridLayout(3, 0));

        jLabel32.setText("Placa");
        jPanel37.add(jLabel32);

        jPanel36.add(jPanel37, java.awt.BorderLayout.WEST);

        jPanel38.setLayout(new java.awt.GridLayout(3, 0));
        jPanel38.add(jTextField1);

        jPanel36.add(jPanel38, java.awt.BorderLayout.CENTER);

        jPanel28.add(jPanel36);

        pnCentral.add(jPanel28, java.awt.BorderLayout.PAGE_END);

        getContentPane().add(pnCentral, java.awt.BorderLayout.CENTER);

        pnObservacao.setLayout(new java.awt.BorderLayout());

        jPanel2.setLayout(new java.awt.BorderLayout());

        jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED), "Observações"));
        jPanel10.setLayout(new java.awt.BorderLayout());

        taObservacoes.setColumns(20);
        taObservacoes.setRows(5);
        jScrollPane1.setViewportView(taObservacoes);

        jPanel10.add(jScrollPane1, java.awt.BorderLayout.NORTH);

        jPanel29.setLayout(new java.awt.BorderLayout());
        jPanel29.add(jLabel30, java.awt.BorderLayout.EAST);

        jPanel10.add(jPanel29, java.awt.BorderLayout.CENTER);

        jPanel2.add(jPanel10, java.awt.BorderLayout.SOUTH);

        pnObservacao.add(jPanel2, java.awt.BorderLayout.SOUTH);

        getContentPane().add(pnObservacao, java.awt.BorderLayout.SOUTH);

        pnBotoes.setLayout(new java.awt.BorderLayout());

        jPanel12.setLayout(new java.awt.GridLayout(2, 0));

        btImprimir.setText("Imprimir");
        btImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btImprimirActionPerformed(evt);
            }
        });
        jPanel12.add(btImprimir);

        btSair.setText("Sair");
        btSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSairActionPerformed(evt);
            }
        });
        jPanel12.add(btSair);

        pnBotoes.add(jPanel12, java.awt.BorderLayout.NORTH);

        getContentPane().add(pnBotoes, java.awt.BorderLayout.EAST);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btImportarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btImportarActionPerformed
        fcSelecionadorDeArquivo = new JFileChooser();
        if (fcSelecionadorDeArquivo.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
            arquivo = fcSelecionadorDeArquivo.getSelectedFile();
            tfArquivo.setText(arquivo.getAbsolutePath());

            try {
                File notaFile = new File(tfArquivo.getText());
                JAXBContext context = JAXBContext.newInstance("br.com.javac.v200.procnfe");


                Unmarshaller unmarshaller = context.createUnmarshaller();

                TNfeProc nfeProc = unmarshaller.unmarshal(new StreamSource(notaFile), TNfeProc.class).getValue();

                tfrRemetente.setText(nfeProc.getNFe().getInfNFe().getEmit().getXNome());
                tfrCidade.setText(nfeProc.getNFe().getInfNFe().getEmit().getEnderEmit().getXMun());
                tfrCnpj.setText(nfeProc.getNFe().getInfNFe().getEmit().getCNPJ());
                tfrEndereco.setText(nfeProc.getNFe().getInfNFe().getEmit().getEnderEmit().getXLgr());

                tfdDestinatario.setText(nfeProc.getNFe().getInfNFe().getDest().getXNome());
                tfdCidade.setText(nfeProc.getNFe().getInfNFe().getDest().getEnderDest().getXMun());
                tfdCnpj.setText(nfeProc.getNFe().getInfNFe().getDest().getCNPJ());
                tfdEndereco.setText(nfeProc.getNFe().getInfNFe().getDest().getEnderDest().getXLgr());

                tfNf.setText(nfeProc.getNFe().getInfNFe().getIde().getNNF());
                tfValorNf.setText(nfeProc.getNFe().getInfNFe().getTotal().getICMSTot().getVProd());

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }//GEN-LAST:event_btImportarActionPerformed

    private void btSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSairActionPerformed
        dispose();
    }//GEN-LAST:event_btSairActionPerformed

    private void tfrCodigoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfrCodigoFocusLost
        tfdCodigo.grabFocus();
        tfrCodigoActionPerformed(null);
    }//GEN-LAST:event_tfrCodigoFocusLost

    private void tfdCodigoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfdCodigoFocusLost
        tfCarga.grabFocus();
        tfdCodigoActionPerformed(null);
    }//GEN-LAST:event_tfdCodigoFocusLost

    private void tfmCPFFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfmCPFFocusLost
        taObservacoes.grabFocus();
    }//GEN-LAST:event_tfmCPFFocusLost

    private void jTextField21FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextField21FocusLost
        tfrCodigo.grabFocus();
    }//GEN-LAST:event_jTextField21FocusLost

    private void tfrCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfrCodigoActionPerformed
        if (!tfrCodigo.getText().equals("")) {
            Cliente cliente = dao.findCliente(Integer.parseInt(tfrCodigo.getText()));
            tfrRemetente.setText(cliente.getNome());
            tfrCidade.setText(cliente.getCidadeantiga());
            tfrCnpj.setText(cliente.getCnpjCpf());
            tfrIe.setText(cliente.getIe());
            tfrEndereco.setText(cliente.getEndereco());
        } else {
            LimparCamposRemetente();
        }
    }//GEN-LAST:event_tfrCodigoActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    }//GEN-LAST:event_jButton1ActionPerformed

    private void tfdCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfdCodigoActionPerformed
        if (!tfdCodigo.getText().equals("")) {
            Cliente cliente = dao.findCliente(Integer.parseInt(tfdCodigo.getText()));
            tfdDestinatario.setText(cliente.getNome());
            tfdCidade.setText(cliente.getCidadeantiga());
            tfdCnpj.setText(cliente.getCnpjCpf());
            tfdIe.setText(cliente.getIe());
            tfdEndereco.setText(cliente.getEndereco());
        } else {
            LimparCamposDestinatario();
        }
    }//GEN-LAST:event_tfdCodigoActionPerformed

    private void tfmCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfmCodigoActionPerformed
        try {
            Motorista mot = daoMot.findMotorista(Integer.parseInt(tfmCodigo.getText()));
            tfmNome.setText(mot.getNome());
        } catch (Exception e) {
            Mensagem.exibirMensagem("Código inválido", "Atenção", true);
        }
    }//GEN-LAST:event_tfmCodigoActionPerformed

    private void tfmCodigoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfmCodigoKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_F2) {
            GUIGridMotorista mot = new GUIGridMotorista(this, true);
            if (mot.alterarDados()) {
                tfmCodigo.setText(mot.getMotSelecionado().toString());
                tfmCodigoActionPerformed(null);
            }
            mot.dispose();
        }
    }//GEN-LAST:event_tfmCodigoKeyPressed

    private void tfrCodigoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfrCodigoKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_F2) {
            GUIGridCliente cli = new GUIGridCliente(this, true);
            if (cli.alterarDados()) {
                tfrCodigo.setText(cli.getClienteSelecionado().toString());
                tfrCodigoActionPerformed(null);
            }
            cli.dispose();
        }
    }//GEN-LAST:event_tfrCodigoKeyPressed

    private void tfdCodigoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfdCodigoKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_F2) {
            GUIGridCliente cli = new GUIGridCliente(this, true);
            if (cli.alterarDados()) {
                tfdCodigo.setText(cli.getClienteSelecionado().toString());
                tfdCodigoActionPerformed(null);
            }
            cli.dispose();
        }
    }//GEN-LAST:event_tfdCodigoKeyPressed

    private void btImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btImprimirActionPerformed
        ctrc c = new ctrc();
        c.setNumero(555);
        c.setTipo("SAIDA");
        c.setNatureza(tfNatureza.getText());
        c.setRemetente(tfrRemetente.getText());

        StringBuffer name = new StringBuffer(" ");
//        name.append("Roloff");

        EmissorLX300 e = new EmissorLX300(c, name, "\\\\IVAN\\EpsonLX-");
        e.emitir();
        e.imprimir();
    }//GEN-LAST:event_btImprimirActionPerformed

    public void IniciaStatusBar() {
        Locale locale = new Locale("pt", "BR");
        GregorianCalendar calendar = new GregorianCalendar();
        SimpleDateFormat formatador = new SimpleDateFormat("dd' de 'MMMMM' de 'yyyy' - 'HH':'mm'Hr'", locale);
        jLabel30.setText(formatador.format(calendar.getTime()));
    }

    public void LimparCamposRemetente() {
        tfrRemetente.setText("");
        tfrCidade.setText("");
        tfrCnpj.setText("");
        tfrIe.setText("");
        tfrEndereco.setText("");
    }

    private void LimparCamposDestinatario() {
        tfdDestinatario.setText("");
        tfdCidade.setText("");
        tfdCnpj.setText("");
        tfdIe.setText("");
        tfdEndereco.setText("");
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup bgFrete;
    private javax.swing.JButton btImportar;
    private javax.swing.JButton btImprimir;
    private javax.swing.JButton btSair;
    private javax.swing.JFileChooser fcSelecionadorDeArquivo;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel16;
    private javax.swing.JPanel jPanel17;
    private javax.swing.JPanel jPanel18;
    private javax.swing.JPanel jPanel19;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel20;
    private javax.swing.JPanel jPanel21;
    private javax.swing.JPanel jPanel22;
    private javax.swing.JPanel jPanel23;
    private javax.swing.JPanel jPanel24;
    private javax.swing.JPanel jPanel25;
    private javax.swing.JPanel jPanel26;
    private javax.swing.JPanel jPanel27;
    private javax.swing.JPanel jPanel28;
    private javax.swing.JPanel jPanel29;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel30;
    private javax.swing.JPanel jPanel31;
    private javax.swing.JPanel jPanel32;
    private javax.swing.JPanel jPanel33;
    private javax.swing.JPanel jPanel34;
    private javax.swing.JPanel jPanel35;
    private javax.swing.JPanel jPanel36;
    private javax.swing.JPanel jPanel37;
    private javax.swing.JPanel jPanel38;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JTextField jTextField11;
    private javax.swing.JTextField jTextField12;
    private javax.swing.JTextField jTextField13;
    private javax.swing.JTextField jTextField14;
    private javax.swing.JTextField jTextField15;
    private javax.swing.JTextField jTextField21;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    private javax.swing.JLabel lbdCodigo;
    private javax.swing.JLabel lbrCidade;
    private javax.swing.JLabel lbrCnpj;
    private javax.swing.JLabel lbrCodigo;
    private javax.swing.JLabel lbrEndereco;
    private javax.swing.JLabel lbrIe;
    private javax.swing.JLabel lbrRemetente;
    private javax.swing.JPanel pnBotoes;
    private javax.swing.JPanel pnCabecalho;
    private javax.swing.JPanel pnCentral;
    private javax.swing.JPanel pnDestinatario;
    private javax.swing.JPanel pnObservacao;
    private javax.swing.JPanel pnRemetente;
    private javax.swing.JRadioButton rbAPagar;
    private javax.swing.JRadioButton rbPago;
    private javax.swing.JTextArea taObservacoes;
    private javax.swing.JTextField tfArquivo;
    private javax.swing.JTextField tfCarga;
    private javax.swing.JTextField tfCodCarga;
    private javax.swing.JTextField tfData;
    private javax.swing.JTextField tfEspecie;
    private javax.swing.JTextField tfNatureza;
    private javax.swing.JTextField tfNf;
    private javax.swing.JTextField tfQtdeNf;
    private javax.swing.JTextField tfValorNf;
    private javax.swing.JTextField tfdCidade;
    private javax.swing.JTextField tfdCnpj;
    private javax.swing.JTextField tfdCodigo;
    private javax.swing.JTextField tfdDestinatario;
    private javax.swing.JTextField tfdEndereco;
    private javax.swing.JTextField tfdIe;
    private javax.swing.JTextField tfmCPF;
    private javax.swing.JTextField tfmCodigo;
    private javax.swing.JTextField tfmNome;
    private javax.swing.JTextField tfrCidade;
    private javax.swing.JTextField tfrCnpj;
    private javax.swing.JTextField tfrCodigo;
    private javax.swing.JTextField tfrEndereco;
    private javax.swing.JTextField tfrIe;
    private javax.swing.JTextField tfrRemetente;
    // End of variables declaration//GEN-END:variables
}
